<!-- Lightbox-Styles und Script -->


<script>
// AJAX-CMS + Lightbox-Integration
document.addEventListener('DOMContentLoaded', () => {
  document.querySelectorAll('.cms-content[data-id]').forEach(el => {
    const id = el.getAttribute('data-id');
    fetch('cms_content.php?id=' + encodeURIComponent(id))
      .then(r => r.text())
      .then(t => {
        el.innerHTML = t;

        // 🔽 Lightbox automatisch für neue CMS-Inhalte aktivieren
        el.querySelectorAll('img').forEach(img => {
          // Nur wenn Bild noch keinen <a> Link hat
          if (!img.closest('a')) {
            const a = document.createElement('a');
            a.href = img.src;
            a.className = 'lightbox';
            img.parentNode.insertBefore(a, img);
            a.appendChild(img);
          }
        });

        // Lightbox initialisieren (erneut nach dem Laden)
        GLightbox({ selector: '.lightbox' });
      })
      .catch(err => {
        console.error('Fehler beim Laden von', id, err);
      });
  });
});
</script>
